package cn.dlc.com.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.dlc.com.config.Config;
import cn.dlc.com.config.ConfigCenter;
import cn.dlc.com.property.ZookeeperProperty;

@RestController
@RequestMapping("config")
public class ConfigContoller {

	// ServerConfig里面已经完成初始化，创建了节点
	@Autowired
	private ConfigCenter configCenter;
	
	@Autowired
	private ZookeeperProperty zk;
	
	/**
	 * 发起请求，将这个东西进行改变
	 * @param config
	 * @return
	 */
	@PostMapping("change")
	public String changeConfig(@RequestBody Config config) throws Exception{
		System.out.println("新的参数： " + config.toString());
		System.out.println("zookeeper的地址： " + zk.getUrl());
		if(config != null) {
			configCenter.updateConfig(zk.getNodePath(), config);
		}
		return "ok";
	}
}
